var Company = {
		getTableData: function(){
			jQuery('.datatable').dataTable({
		        sAjaxSource: appCtx + "/web/company/loadData",
		        oLanguage: {
		            sUrl: appCtx + '/flatpoint/js/zh_CN.json',
		        },
		        bSort: false,                        // 是否排序功能
		        bFilter: false,                       // 过滤功能
		        bPaginate: true,                     // 翻页功能
		        bInfo: true,                         // 页脚信息
		        bProcessing: true,                   //显示正在加载中
		        bServerSide: true,                   //开启服务器模式
		        sPaginationType: "full_numbers",    //分页策略
		        bAutoWidth: false,                  // 是否非自动宽度
		        sServerMethod: "POST",              //请求方式为post 主要为了防止中文参数乱码
		        //sPaginationType: "bootstrap",
		        sDom: '<"top">rt<"tableFooter"lip<"clear">',
		        fnServerParams : function (aoData) {
		            aoData.push({"name": "name", "value":jQuery("#name").val()});
		            aoData.push({"name": "address", "value":jQuery("#address").val()});
		        },
		        aoColumns:[{
		            mData : "id",
		            sDefaultContent : "",
		            sTitle : "#"
		        },{
		            mData : "name",
		            sDefaultContent : "",
		            sTitle : "姓名"
		        },{
		            mData : "address",
		            sDefaultContent : "",
		            sTitle : "地址"
		            
		        },{
		            mData : "email",
		            sDefaultContent : "",
		            sTitle : "邮箱"
		        },{
		            mData : "createdAt",
		            sDefaultContent : "",
		            sTitle : "创建日期",
		            mRender: function(value, type ,data){
		            	if (value) {
			            	return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
		            	}
		            }
		            
		        },{
		            mData : "id",
		            sDefaultContent : "",
		            sTitle : "操作",
		            mRender: function(value, type ,data){
		            	return '<a class="btn edit" href="javascript:Company.editCompany('+ value + ')"><i class="icon-edit"></i></a>\
		            	        <a class="btn edit" href="javascript:Company.deleteCompany('+ value + ')"><i class="icon-trash"></i></a>'
		            }
		            
		        }]
		    })
		},
			
    // 查询按钮
    queryList : function(){
    	jQuery(".datatable").dataTable().fnDraw();
    }, 
    
    editCompany : function(id){
    	Fitz.loadForm(appCtx + "/web/company/edit/" + id);
    },
    
    validateCompany: function(cbk) {
    	var params = {};
    	params.rules = {
    			name: {
    				required: true
    			},
    			address: {
    				required: true
    			},
    			email: {
    				email: true
    			}
    	}
    	params.messages={
    			name: {
    				required: "城市名称不能为空！"
    			},
    			address: {
    				required: "地址不能为空！"
    			},
    			email: {
    				email: "格式不正确！"
    			}
    	}
    	params.form = jQuery("#company");
    	params.cbk = cbk;
    	Fitz.validate(params);
    },
    
    deleteCompany: function(id) {
    	Fitz.confirm("确定要删除？", function(){
    		jQuery.ajax({
				url: appCtx + "/web/company/delete/" + id,
				type: 'post',
				dataType: "json",
				success: function(json) {
					if (json.code == "0") {
						Company.queryList();
					} else {
						Fitz.alert(json.message);
					}
				},
				error: function(xhr, textStatus, errorThrown){
					alert(errorThrown);
				}
			});
    	});
    }
}

